<template>
	<view>
		<view class="list" v-if="combinationList.length">
			<view class="item acea-row row-between-wrapper" v-for="(item,index) in combinationList" :key='index'
				@tap="openSubcribe(item)">
				<view class="pictrue">
					<image :src="item.image"></image>
				</view>
				<view class="text">
					<view class="name line2">{{item.title}}</view>
					<view class="bottom acea-row row-between row-bottom">
						<view class="y_money">
							<view class="price">{{$t(`￥`)}}{{item.product_price}}</view>
							<view class="money">{{$t(`￥`)}}<text class="num">{{item.price}}</text></view>
						</view>
						<view class="bnt acea-row row-center-wrapper" v-if="item.stock>0&&item.quota>0">
							<view class="light">
								<image src="@/pages/activity/static/lightning.png"></image>
							</view>
							<view class="num">{{item.people}}{{$t(`人团`)}}</view>
							<view class="go">{{$t(`去拼团`)}}</view>
						</view>
						<view class="bnt gray acea-row row-center-wrapper" v-else>{{$t(`已售罄`)}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCombinationList
	} from '@/api/activity.js';
	export default {
		name: "groupBuying",
		data() {
			return {
				combinationList: []
			};
		},
		mounted() {
			this.getCombinationList();
		},
		methods: {
			getCombinationList: function() {
				var that = this;
				getCombinationList().then(function(res) {
					var combinationList = that.combinationList;
					that.combinationList = combinationList.concat(res.data);
				}).catch(() => {
					that.loading = false
				})
			},
			openSubcribe: function(item) {
				let page = item;
				// #ifndef MP
				uni.navigateTo({
					url: `/pages/activity/goods_combination_details/index?id=${item.id}`
				});
				// #endif
				// #ifdef MP
				uni.showLoading({
					title: this.$t(`正在加载中`),
				})
				openPinkSubscribe().then(res => {
					uni.hideLoading();
					uni.navigateTo({
						url: `/pages/activity/goods_combination_details/index?id=${item.id}`
					});
				}).catch(() => {
					uni.hideLoading();
				});
				// #endif
			},
		}
	}
</script>

<style lang="scss">
	.list {
		.item {
			width: 710rpx;
			height: 230rpx;
			background-color: #fff;
			border-radius: 14rpx;
			padding: 0 22rpx;
			margin: 20rpx auto 18rpx auto;

			.pictrue {
				width: 186rpx;
				height: 186rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
			}

			.text {
				width: 440rpx;

				.name {
					color: #333;
					font-size: 30rpx;
					line-height: 38rpx;
					height: 70rpx;
				}

				.bottom {
					margin-top: 10rpx;

					.y_money {
						font-size: 24rpx;
						color: #999;

						.price {
							text-decoration: line-through;
						}

						.money {
							color: var(--view-priceColor);
							font-weight: 600;

							.num {
								font-size: 34rpx;
							}
						}
					}

					.bnt {
						height: 58rpx;
						font-size: 24rpx;
						text-align: center;
						position: relative;
						background-color: var(--view-theme);
						border-radius: 28rpx;

						.light {
							position: absolute;
							width: 28rpx;
							height: 58rpx;
							top: 0;
							left: 50%;
							margin-left: -8rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.num {
							width: 120rpx;
							background-color: rgba(255, 255, 255, 0.85);
							color: var(--view-theme);
							height: 100%;
							line-height: 58rpx;
							border-radius: 28rpx 0 14rpx 28rpx;
						}

						.go {
							width: 112rpx;
							background-color: var(--view-theme);
							height: 100%;
							line-height: 58rpx;
							border-radius: 0 28rpx 28rpx 0;
							color: #fff;
						}

						&.gray {
							width: 148rpx;
							background-color: #cccccc;
							color: #fff;
						}
					}
				}
			}
		}
	}
</style>